package com.zeus.config;

import com.zeus.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 冯扬龙
 * @date 2021/6/9 21:40
 */
@Configuration
public class MyConfig implements WebMvcConfigurer {

//解决跨域问题，通过全局配置不使用注解
    @Bean
    public WebMvcConfigurer crosConfigure(){
        return new WebMvcConfigurer() {
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                registry.addMapping("/**").
                         allowedHeaders("*").
                        allowedMethods("*").
                        allowCredentials(true).
                        allowedOrigins("*").
                        maxAge(3600l);
            }
        };
    }


//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        //注册TestInterceptor拦截器
//        InterceptorRegistration registration =
//                registry.addInterceptor(new LoginInterceptor());
//        registration.addPathPatterns("/**");                      //所有路径都被拦截
//        registration.excludePathPatterns(                         //添加不拦截路径
//                "/**/login.html",            //登录
//                "/**/index.html",            //html静态资源
//                "/**/*.js",              //js静态资源
//                "/**/*.css",             //css静态资源
//                "/**/*.woff",
//                "/**/*.ttf",
//                "/**/*.png",
//                "/**/*.jpg",
//                "loginIn",
//                "user/reg",
//                "post/queryPointAndAllPost"
//        );
//    }
}
